package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.SysCourseSort;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.mapper.SysCourseSortMapper;
import com.hl.sfzy.service.SysCourseSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("sysCourseSortService")
public class SysCourseSortServiceImpl implements SysCourseSortService {
    @Autowired
    private SysCourseSortMapper sysCourseSortMapper;

    @Override
    public int add(SysCourseSort entity) {
        return sysCourseSortMapper.insert(entity);
    }

    @Override
    public int edit(SysCourseSort entity) {
        return sysCourseSortMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return sysCourseSortMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return sysCourseSortMapper.deleteBatch(ids);
    }

    @Override
    public List<SysCourseSort> find(SysCourseSort entity) {
        return sysCourseSortMapper.select(entity);
    }

    @Override
    public SysCourseSort findById(Integer id) {
        return sysCourseSortMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, SysCourseSort entity) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<SysCourseSort> list = sysCourseSortMapper.select(entity);
        PageInfo<SysCourseSort> pageInfo = new PageInfo<>(list);
        HashMap<String, Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }
}